/*
 
 * 提现管理
 * 
 * 2017-11-18
 * 
 * wangweiruning
 * 
 * */

$(function(){
	var phone=sessionStorage.getItem("phone");
		$.ajax({
			type:"post",
			url:"https://jindi163.com:8443/JDLot/user/commision/list",
			data:{
			pay_status:0,//支付状态
			PageNum:1,
			PageSize:10
		},
			dataType:'json', 
			contentType:"application/json",
			xhrFields: {
   						 withCredentials: true
						},
					crossDomain: true,
		success:function(data){
			var data= data.datas;
			console.log(data)
			var htmlp='<tr><th>操作时间</th><th>提现金额</th><th>提现到</th><th>操作</th></tr>'
			var htmls="";
		    var total=(data.length)/10;

			for (var i=0;i<data.length;i++) {
				var item=data[i];
				htmls+='<tr><td><span>'+item.commision_time+
				'</span><span class="hide_tikuan" style="position:fixed;top:-99999px">'+item.uc_id+'</span></td><td class="moneys">'+item.commision+
				'</td><td>'+item.content+
				'</td><td><input type="text" value="" class="reject"  placeholder="请输入驳回理由"><button class="go_back">驳回</button><button class="agrees">同意</button>'+
				'</td></tr>';
			}
			$("#kongs").html(htmlp);
			$("#list_shows").html(htmls);
			
			boui();
			isok();
			 $(".sPageCode").createPage({  

                    pageCount:total,  
                    current:1,  
                    backFn:function(pageIndex){  
                        $("#list_shows").empty();  
                        var start =pageIndex;//开始的页码数
							
			$.ajax({
			type:"post",
			url:"https://jindi163.com:8443/JDLot/user/commision/list",
			data:{
			pay_status:0,//支付状态
			PageNum:start,
			PageSize:10
		},
			dataType:'json', 
			contentType:"application/json",
			xhrFields: {
   						 withCredentials: true
						},
					crossDomain: true,
		success:function(data){
			var data= data.datas;
			var htmls="";
		    var total=(data.length)/10;
			for (var i=0;i<data.length;i++) {
				var item=data[i];
				htmls+='<tr><td><span>'+item.commision_time+
				'</span><span class="hide_tikuan" style="position:fixed;top:-99999px">'+item.uc_id+'</span></td><td class="moneys">'+item.commision+
				'</td><td>'+item.content+
				'</td><td><input type="text" value="" class="reject" placeholder="请输入驳回理由"><button class="go_back">驳回</button><button class="agrees">同意</button>'+
				'</td></tr>';
			}
			$("#list_shows").html(htmls);
			boui()	
			isok()
			}
		})
							
								
			}
         })
			
			function boui(){ 
				$(".go_back").each(function(i){
					$(this).click(function(){
				
					var index =i;
					var uc_id=$(".hide_tikuan").eq(index).text();
					var pay_money=$(".moneys").eq(index).text();
					var reject= $(".reject").eq(index).val();
					console.log(uc_id+"===="+pay_money+"==="+reject)
					$.ajax({
						type:"post",
						url:"https://jindi163.com:8443/JDLot/user/commision/update",
						async:true,
						dataType:'json', 
						contentType:"application/json",
						data:{
							pay_status:2,
							uc_id:uc_id,
							reject_info:reject,//驳回的条件----原因
						},
						xhrFields: {
   						 withCredentials: true
						},
					crossDomain: true,
						success:function(res){
							console.log(res)
							if(res.msgContext=="updateSuc"){
								return
							}else{
								alert("驳回")
							}
						}
						
					});
				})
			})
				}
			
			function isok(){
				$(".agrees").each(function(i){
					$(this).click(function(){
				
					var index =i;
					var uc_id=$(".hide_tikuan").eq(index).text();
					console.log(uc_id)
					var pay_money=$(".moneys").eq(index).text();
					var reject= $(".reject").eq(index).val();
					console.log(uc_id)
					$.ajax({
						type:"post",
						url:"https://jindi163.com:8443/JDLot/user/commision/update",
						async:true,
						dataType:'json', 
						contentType:"application/json",
						data:{
							pay_status:1,
							uc_id:uc_id,
							reject_info:reject
						},
						xhrFields: {
   						 withCredentials: true
						},
					    crossDomain: true,
						success:function(res){
							console.log(res)
							if(res.msgContext=="updateSuc"){
								alert("操作成功")
							}else{
								return
							}
						}
						
					});
				})
			})
				}
			
		}
	
		})
})
